﻿@{
    ViewBag.Title = "ChiTiet";
    Layout = "~/Views/Shared/Admin/_AdminLayout.cshtml";
}
@model BabyToys.Models.HoaDon
<div style="background: #fff; text-align: right; height: 40px; width: 100%; border: 1px solid #ccc;">
    <span style="font-size: 18px; font-weight: bold; float: left; padding-top: 17px; padding-left: 15px;">CHI TIẾT HÓA ĐƠN</span>
    <table style="float: right; font-size: 11px; color: #262626;">
        <tr>
            <td class="control">
                <a href="~/AdminHoaDon" class="large button green input">Quay lại</a>
            </td>
        </tr>
    </table>
</div>
<div class="Main_nhap" style="">
    <div class="Main_nhap_left">
        <div style="padding-top: 10px;">
            <div style="border: 1px solid #ccc; background: #e7e7e7; width: 99%; padding: 8px; min-height: 200px; text-shadow: #fff 0px 1px 0px;">
                <table class="Conten_main_sanpham" cellpadding="0" cellspacing="0" style="border: 1px solid #fff;">
                    <tr class="row">
                        <td class="box_title">ID</td>
                        <td class="box_object">
                            @Model.IdHoaDon
                        </td>
                    </tr>
                    <tr class="row">
                        <td class="box_title">Ngày lập</td>
                        <td class="box_object">
                            @{string NgayLap=String.Format("{0:d/M/yyyy HH:mm:ss}",@Model.NgayLapHD);}
                            @NgayLap
                        </td>
                    </tr>
                    <tr class="row">
                        <td class="box_title">Tên khách hàng</td>
                        <td class="box_object"></td>
                    </tr>
                    <tr class="row">
                        <td class="box_title">Địa chỉ</td>
                        <td class="box_object">
                            @Model.DiaChiGiaoHang
                        </td>
                    </tr>
                    <tr class="row">
                        <td class="box_title">Email</td>
                        <td class="box_object"></td>
                    </tr>
                    <tr class="row">
                        <td class="box_title">Số điện thoại</td>
                        <td class="box_object"></td>
                    </tr>
                    <tr class="row">
                        <td class="box_title">Trạng thái</td>
                        <td class="box_object">
                            <select id="TrangThai" onchange="CapNhatTrangThai(@Model.IdHoaDon)">
                                <option value="1" @if (Model.TrangThai == 1)
                                                  { @:selected="selected" 
                               }>Chưa liên hệ</option>
                                        <option value="2" @if (Model.TrangThai == 2)
                                                          { @:selected="selected" 
                               }>Chưa giao hàng</option>
                                        <option value="3" @if (Model.TrangThai == 3)
                                                          { @:selected="selected" 
                               }>Đã giao hàng</option>
                            </select>
                            <script>
                                function CapNhatTrangThai(id) {
                                    var x = confirm("Bạn có chắc muốn thay đổi trạng thái của hóa đơn này?");
                                    if (x == true) {
                                        var id = id;
                                        var trangthai = $("#TrangThai").val();
                                        var submitData = {
                                            id: id,
                                            trangthai: trangthai
                                        }
                                        //alert("chọn: "+trangthai+","+id);
                                        $.ajax({
                                            type: "POST",
                                            contentType: "application/json",
                                            url: "/AdminHoaDon/CapNhatTrangThai",
                                            data: JSON.stringify(submitData),

                                        });
                                        Reload();
                                    } else {
                                        window.location.reload();
                                    }

                                }
                                function Reload() {
                                    alert("Cập nhật thành công");
                                }
                    </script>
                        </td>
                    </tr>
                    <tr class="row">
                            <td class="box_title">Tổng tiền hàng</td>
                            <td class="box_object">
                                @Model.TienHang
                            </td>
                        </tr>
                    <tr class="row">
                            <td class="box_title">Phí vận chuyển</td>
                            <td class="box_object">
                                @Model.PhiVanChuyen
                            </td>
                    </tr>
                    <tr class="row">
                            <td class="box_title">Giảm giá</td>
                            <td class="box_object">
                                @Model.TienKhuyenMai
                            </td>
                    </tr>
                    <tr class="row">
                            <td class="box_title">Tổng giá trị</td>
                            <td class="box_object">
                                @Model.TongTien
                            </td>
                   </tr>
                    <tr class="row">
                        <td colspan="2" style="text-align:center;">
                            <table cellspacing="0" rules="rows" class="rows" border="1" style="width:100%;border-collapse:collapse;">
                                <tbody>
                                    <tr class="item_title" style="color: White; background-color: #CCCCCC; font-family: Tahoma; font-size: 12px; font-weight: bold; height: 30px;">
                                        <th>id</th>
                                        <th>Sản phẩm</th>
                                        <th>Số lượng</th>
                                        <th>Thành tiền</th>
                                    </tr>
                                    
                                
                                @foreach(var hoadon in Model.ChiTietHoaDons)
                                {
                                    <tr class="item_row" style="border-color: #F0F0F0; border-style: Solid; height: 40px;">
                                        <td class="item_float">@hoadon.Id</td>
                                        <td class="item_float">@hoadon.SanPham.TenSP</td>
                                        <td class="item_float">@hoadon.SoLuong</td>
                                        <td class="item_float">@hoadon.ThanhTien</td>
                                    </tr>
                                }
                                </tbody>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
